PHP

How to pass an object of class as an argument in PHP | PHP programs

How to pass an object of class as an argument in PHP | PHP programs

How to pass an object of class as an argument in PHP | PHP programs

 We will demonstrate how we can pass an object as an argument to the non-member function.

<?php


class Student
{
    public $Id;
    public $Name;
}

function Set(Student $S, $id, $name)
{
    $S->Id = $id;
    $S->Name = $name;
}
function Display(Student $S)
{
    printf("Id  : " . $S->Id . "<br>");
    printf("Name: " . $S->Name . "<br>");
}

$S = new Student();

Set($S, 101, "Rahul");
Display($S);

?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community